﻿using LibraryManagement.Core.Services;
using LibraryManagement.Domain.UserManagement;
using LibraryManagement.Helpers;

namespace LibraryManagement.Membership
{
    public class UserManager
    {
        private static User _user;
        public static User CurrentUser
        {
            get
            {
                return _user;
            }
            private set
            {
                _user = value;
            }
        }

        public static bool Authenticate(string userName, byte[] password)
        {
            return Authenticate(new User(userName, password));
        }

        public static bool Authenticate(string userName, string password)
        {
            return Authenticate(new User(userName, password.ToHash()));
        }

        public static bool Authenticate(User user)
        {
            _user = user;
            return true;
        }

        public bool RegisterUser(string firstName, string lastName, string userName, string password, string email, string code, Role role)
        {
            return RegisterUser(firstName, lastName, userName, password.ToHash(), email, code, role);
        }

        public bool RegisterUser(string firstName, string lastName, string userName, byte[] password, string email, string code, Role role)
        {
            return RegisterUser(new User(userName, password)
                {
                    FirstName = firstName,
                    LastName = lastName,
                    UserName = userName, 
                    Password = password,
                    Email = email,
                    Code = code,
                }, role);
        }

        public bool RegisterUser(User user, Role role)
        {
            return true;
        }
    }
}
